//
//  OtherLoginView.m
//  ShowYork
//
//  Created by hxh on 2020/8/24.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "OtherLoginView.h"

typedef void(^doneBlock)(NSInteger index);


@interface OtherLoginView ()
//@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIButton *qqBtn;
@property (nonatomic,strong)UIButton *wechatBtn;
@property (nonatomic,strong)UIButton *appleBtn;
//@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,copy)doneBlock done;
@end


@implementation OtherLoginView

- (instancetype)initWithCompleteBlock:(void (^)(NSInteger index))completeBlock{
    if (self = [super init]) {
        
        [self setUI];
        if (completeBlock) {
            self.done = ^(NSInteger index) {
                completeBlock(index);
            };
        }
        
    }
    return self;
}

- (void)setUI{
    
//    self.line = [[UIView alloc]init];
//    self.line.backgroundColor = [UIColor lightGrayColor];
//    [self addSubview:self.line];
//
//    self.titleLb = [[UILabel alloc]init];
//    self.titleLb.text = @"第三方帐号登录";
//    self.titleLb.backgroundColor = [UIColor whiteColor];
//    self.titleLb.textAlignment = NSTextAlignmentCenter;
//    self.titleLb.font = font(14);
//    [self addSubview:self.titleLb];
//
    self.qqBtn = [[UIButton alloc]init];
    [self.qqBtn setImage:[UIImage imageNamed:@"login_qq_tag"] forState:UIControlStateNormal];
    [self.qqBtn setImage:[UIImage imageNamed:@"login_qq_tag"] forState:UIControlStateHighlighted];
    self.qqBtn.tag = 1;
    [self.qqBtn addTarget:self action:@selector(loginMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.qqBtn];
    
    self.wechatBtn = [[UIButton alloc]init];
    [self.wechatBtn setImage:[UIImage imageNamed:@"login_wechat_tag"] forState:UIControlStateNormal];
    [self.wechatBtn setImage:[UIImage imageNamed:@"login_wechat_tag"] forState:UIControlStateHighlighted];
    self.wechatBtn.tag = 0;
    [self.wechatBtn addTarget:self action:@selector(loginMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.wechatBtn];
    
    self.appleBtn = [[UIButton alloc]init];
    [self.appleBtn setImage:[UIImage imageNamed:@"login_apple_tag"] forState:UIControlStateNormal];
    [self.appleBtn setImage:[UIImage imageNamed:@"login_apple_tag"] forState:UIControlStateHighlighted];
    self.appleBtn.tag = 2;
    [self.appleBtn addTarget:self action:@selector(loginMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.appleBtn];
//
//    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(15);
//        make.right.equalTo(self).offset(-15);
//        make.height.mas_equalTo(0.5);
//        make.top.equalTo(self);
//    }];
    
//    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.line);
//        make.height.mas_equalTo(30);
//        make.width.mas_equalTo(150);
//    }];
    
    [self.qqBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.top.equalTo(self);
        make.bottom.equalTo(self);
        make.centerX.equalTo(self);
    }];
    
    [self.wechatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.centerY.equalTo(self.qqBtn);
        make.right.equalTo(self.qqBtn.mas_left).offset(-16);
    }];
//
    [self.appleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.centerY.equalTo(self.qqBtn);
        make.left.equalTo(self.qqBtn.mas_right).offset(16);
    }];
}

- (void)loginMethod:(UIButton *)button{
    if (self.done) {
        self.done(button.tag);
    }
}

@end
